package com.xm.servlet.background.warehouse;

import com.google.gson.Gson;
import com.xm.entity.CommodityWarehouse;
import com.xm.entity.Page;
import com.xm.service.background.WarehouseService;
import lombok.SneakyThrows;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

/**
 * @author 田顺琪
 * @Date 2024-01-03
 */
@WebServlet(name = "WareHouseServlet", value = "/background/warehouse")
public class WareHouseServlet extends HttpServlet {
    private final WarehouseService service=new WarehouseService();
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        int warehouseId=Integer.parseInt(req.getParameter("warehouseId"));
        Page<CommodityWarehouse> list = service.getCondition(1,7,warehouseId,"");
        System.out.println(new Gson().toJson(list));
        resp.getWriter().print(new Gson().toJson(list));
    }

    @SneakyThrows
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp){
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html;charset=utf-8");
        resp.setCharacterEncoding("utf-8");
        int inventory=Integer.parseInt(req.getParameter("inventory"));
        int limit=Integer.parseInt(req.getParameter("limit"));
        int commodityId=Integer.parseInt(req.getParameter("commodityId"));
        resp.getWriter().println(service.reviseCommodityWarehouse(inventory,limit,commodityId));
    }
}
